package com.ruoyi.business.service.impl;

import java.util.List;

import com.ruoyi.bizsys.domain.ZollectionExcludePhone;
import com.ruoyi.business.util.PhoneUtil;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.business.domain.UnionpayAccount;
import com.ruoyi.business.domain.UnionpayAddress;
import com.ruoyi.business.domain.UnionpayChargebacksFlow;
import com.ruoyi.business.domain.UnionpayCustomer;
import com.ruoyi.business.domain.UnionpayMobile;
import com.ruoyi.business.domain.UnionpayRepaymentPlan;
import com.ruoyi.business.mapper.BCollectionMapper;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;


/**
 * 
 * @author victor
 *
 */
@Service
public class CollectionDBServiceImpl {
	
	@Autowired
	private BCollectionMapper collectionMapper;
	
	/**
	 * 删除旧的入催数据
	 */
	@DataSource(DataSourceType.COLLECTION)
	public void delectCollectionInfo(){
		collectionMapper.deleteUnionpayAccount();
		collectionMapper.deleteUnionpayAddress();
		collectionMapper.deleteUnionpayChargebacksFlow();
		collectionMapper.deleteUnionpayCustomer();
		collectionMapper.deleteUnionpayMobile();
		collectionMapper.deleteUnionpayRepaymentPlan();
	}
	
	/**
	 * 保存催收数据
	 */
	@DataSource(DataSourceType.COLLECTION)
	public void saveCollectionInfo(UnionpayCustomer unionpayCustomer, List<UnionpayAddress> unionpayAddresses, 
			List<UnionpayMobile> unionpayMobiles, List<UnionpayAccount> unionpayAccounts, 
			List<UnionpayRepaymentPlan> unionpayRepaymentPlans, List<UnionpayChargebacksFlow> unionpayChargebacksFlows){
		
		collectionMapper.insertUnionpayCustomer(unionpayCustomer);
		
		for(UnionpayAddress unionpayAddress : unionpayAddresses){
			collectionMapper.insertUnionpayAddress(unionpayAddress);;
		}
		for(UnionpayMobile unionpayMobile : unionpayMobiles){
			unionpayMobile.setConTel(PhoneUtil.formatPhone(unionpayMobile.getConTel()));
			collectionMapper.insertUnionpayMobile(unionpayMobile);;
		}
		for(UnionpayAccount unionpayAccount : unionpayAccounts){
			collectionMapper.insertUnionpayAccount(unionpayAccount);
		}
		for(UnionpayRepaymentPlan unionpayRepaymentPlan : unionpayRepaymentPlans){
			collectionMapper.insertUnionpayRepaymentPlan(unionpayRepaymentPlan);;
		}
		for(UnionpayChargebacksFlow unionpayChargebacksFlow : unionpayChargebacksFlows){
			collectionMapper.insertUnionpayChargebacksFlow(unionpayChargebacksFlow);;
		}
		
		unionpayAddresses.clear();
		unionpayMobiles.clear();
		unionpayRepaymentPlans.clear();
		unionpayChargebacksFlows.clear();
	}

	@DataSource(DataSourceType.COLLECTION)
	public List<ZollectionExcludePhone> getDataForCallResult(){
		return collectionMapper.getDataForCallResult(DateUtils.dateTimeNow("yyyy-MM-dd")+" 00:00:00");
	}

}
